﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Scytale
{

    class World
    {
        private Dictionary<Type, List<Element>> worldElements = new Dictionary<Type, List<Element>>();

        public World()
        {

        }

        public Dictionary<Type, List<Element>> getWorldElements()
        {
            return worldElements;
        }

        public bool containsElement(Element e)
        {
            Type t = e.GetType();
            List<Element> list;
            if (worldElements.TryGetValue(t, out list))
            {
                return list.Contains(e);
            }
            return false;
        }

        public bool addElement(Element e)
        {
            Type t = e.GetType();
            List<Element> list;
            if (worldElements.TryGetValue(t, out list))
            {
                if (list.Contains(e))
                {
                    return false;
                }
                else
                {
                    list.Add(e);
                    return true;
                }
            }
            else
            {
                list = new List<Element>();
                worldElements.Add(t, list);
                list.Add(e);
                return true;
            }
        }

        public bool removeElement(Element e)
        {
            Type t = e.GetType();
            List<Element> list;
            if(worldElements.TryGetValue(t, out list)) {
                if(list.Contains(e)) 
                {
                    list.Remove(e);
                    return true;
                } 
                else 
                {
                    return false;
                }
            }
            return false;
        }
    }
}
